package com.blb.exam.student.controller;

import com.blb.common.controller.BaseServlet;
import com.blb.common.entity.Question;
import com.blb.common.entity.QuestionSet;
import com.blb.common.utils.SpringUtils;
import com.blb.exam.student.service.QuetionService;
import com.blb.exam.student.service.QuetionSetService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/quetion.do")
public class QuetionServlet extends BaseServlet {

    private QuetionService quetionService = SpringUtils.getBean(QuetionService.class);
    private QuetionSetService quetionSetService = SpringUtils.getBean(QuetionSetService.class);

    public void findByQuetionSetId(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
        String id = req.getParameter("id");
        if(id != null){
            List<Question> quetions = quetionService.findByQuetionSetId(Integer.parseInt(id));
            req.setAttribute("quetions", quetions);
            QuestionSet quetionSet = quetionSetService.findById(Integer.parseInt(id));
            req.setAttribute("quetionSet",quetionSet);
            req.getRequestDispatcher("quetion.jsp").forward(req,resp);
        }

    }
}
